<template>
    <el-dialog :close-on-click-modal="false"  ref="dialogform" :title="title" :visible.sync="dialogVisible" width="95%" :before-close="handleClose">
        <InspectionSheetAudit :userType="'FARMER'" :isEdit="isEdit" :data="ruleForm" @closeForm="cancel">
        </InspectionSheetAudit>
        <span slot="footer" class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
        </span>
    </el-dialog>
</template>

<script>
import InspectionSheetAudit from "@/components/InspectionSheetAudit";
export default {
    components: { InspectionSheetAudit },
    props: {
        addEditFlag: {
            type: String,
            default: () => {
                return 'add'
            }
        },
        data: {
            type: Object,
            default: () => {
                return {}
            }
        },
        title: {
            type: String,
            default: () => {
                return '检验单'
            }
        },
        dialogVisible: {
            type: Boolean,
            default: () => {
                return false
            }
        }
    },
    data() {
        return {
            isEdit: true,
            ruleForm: {}
        }
    },
    computed: {

    },
    watch: {
        dialogVisible(v) {
            v && this.initData()
        }
    },

    mounted() { },
    methods: {
        initData() {
            this.ruleForm = { ...this.data }
            this.isEdit = false;
            this.$nextTick(() => {
                this.isEdit = true;
            })
        },
        //取消关闭
        cancel() {
            this.ruleForm = {};
            this.isEdit = false;
            this.$emit("closeDialog")
        },
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => { this.cancel() })
                .catch(_ => { });
        }
    }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
    margin-top: 3vh !important;
    height: 94vh;

    .el-dialog__body {
        height: calc(100% - 113px);
    }
}
</style>